<template>
    <view class="travelitem item">
        <view class="store flexb">
            <view class="store_name flexb">
                <image class="icon" :src="imgpath + 'store_icon.png?v=' + imgVersion" mode="aspectFit" > </image>
                <view class="txt">{{ objInfo.company }}</view>
            </view>
            <view class="order_state" >{{getState(objInfo)}}</view>
        </view>
        <view class="order-content" @click="toLink('order')">
            <view class="order-info flexbox">
                <view class="flexl order_detail flexbox">
                    <view class="pic loadingImg">
                        <image
                            :src="objInfo.product.litpic || defaultImg"
                            @error="objInfo.product.litpic = defaultImg"
                            mode="aspectFill"
                        />
                        <view class="tag">{{ orderTypename(objInfo) }}</view>
                    </view>
                    <view class="detail">
                        <view class="h4">{{ objInfo.title }}</view>
                        <view class="info">
                            <view class="p">{{ objInfo.product.title }}</view>
                            <view class="p">出行日期：{{timeTrans(objInfo)}}</view>
                        </view>
                    </view>
                </view>
                <view class="flexr order_count">
                    <view class="p_pirce">{{globalData.appConfig && globalData.appConfig.currency && globalData.appConfig.currency.symbol || '￥'}}{{ objInfo.unitprice }}</view>
                    <view class="p_count">x{{ objInfo.procount }}</view>
                    <view class="pstate" v-if="objInfo.orderstate == 8 || objInfo.orderstate == 9">{{ objInfo.orderstate == 8 ? '退款中' : '退款成功' }}</view>
                </view>
            </view>
            <view class="order-pay flexbox">
                <view>实付：</view><view class="pay_price">{{ globalData.appConfig && globalData.appConfig.currency && globalData.appConfig.currency.symbol || '￥'  }}<view class="b">{{ objInfo.orderprice.split('.')[0] }}<text v-if="objInfo.orderprice.includes('.')">.{{ objInfo.orderprice.split('.')[1] }}</text></view></view>
            </view>
        </view>
        <view class="orderBtns" v-if="objInfo.orderstate != '3'">
            <template v-if="objInfo.orderstate == '0'">
                <view class="btn cancel" @click="toLink('cancel')">取消订单</view>
                <view class="btn share"  @click="toLink('pay_other')" v-if="travelConfig && travelConfig.peerpayState == 1">找人付</view>
                <view class="btn pay" @click="toLink('pay')">去付款</view>
            </template>
            <template v-else-if="objInfo.orderstate == '1'">
                <view class="btn todetail borderBtn" @click="toLink('showCode')">查看券码</view>
            </template>
            <template v-else-if="objInfo.orderstate == '3'">
                <view class="btn comment borderBtn" @click="toLink('comment')">评价</view>
            </template>
            <template v-else-if="objInfo.orderstate == '7' || objInfo.orderstate == '9'">
                <view class="btn rebuy" @click="toLink('rebuy')">再次购买</view>
            </template>
            <template v-else-if="objInfo.orderstate == '8'">
                <view class="btn cancel_tui"  @click="toLink('refund_cancel')">取消退款</view>
                <view class="btn todetail borderBtn" @click="toLink('showCode')">查看券码</view>
            </template>
        </view>
    </view>
</template>

<script>
    const app = getApp();
    export default{
        props:{
            objInfo:{
                type:Object,
                default:{
                    
                }
            },
            ind:{
                type:Number,
                default:0
            },
            travelConfig:{
                type:Object,
                default:{}
            }
        },
        computed:{
            getState(){
                return function(order){
                    const that = this;
                    let orderstate = order.orderstate;
                    let stateText = '';
                    switch(orderstate){
                        case '0':
                            stateText = '待付款';
                            break;
                        case '1':
                            stateText = '待使用';
                            break;
                        case '3':
                            stateText = '交易成功';
                            break;
                        case '7':
                            stateText = '已取消';
                            break;
                        case '8':
                            stateText = '交易关闭';
                            break;
                        case '9':
                            stateText = '交易关闭';
                            break;
                    }
                    return stateText
                }
            },
            orderTypename(){
                return function(order){
                    const that = this;
                    let orderType = order.type;
                    let typename = '';
                    switch(orderType){
                        case '1':
                            typename = '景点门票'
                            break
                        case '2':
                            typename = order.subtype ? '一日游' : '跟团游'
                            break
                        case '3':
                            typename = '酒店/民宿'
                            break
                        case '4':
                            typename = '签证'
                            break
                    }

                    return typename
                }
            },
             // 时间戳转换
             timeTrans(){
                return function(order){
                    let timestr = order.walktime
                    const dateFormatter = app.dateFormatter(timestr);
                    const year = dateFormatter.year;
                    const month = dateFormatter.month;
                    const day = dateFormatter.day;
                    const hour = dateFormatter.hour;
                    const minute = dateFormatter.minute;
                    const second = dateFormatter.second;
                    
                    let today_dateFormatter = app.dateFormatter(parseInt(new Date().valueOf() / 1000));
                    const today_year = today_dateFormatter.year;
                    const today_month = today_dateFormatter.month;
                    let showStr = '';
                    if (new Date(timestr * 1000).toDateString() === new Date().toDateString()) {
                        showStr = '今天 ' 
                    }else  if(year == today_year){
                        if(order.orderstate > 5){
                            showStr = month + '月' + day + '日'  ;
                        }else{
                            showStr = month + '月' + day + '日 '  ;
                        }
                    }else{
                        showStr = year + '/' + month + '/' + day + ' '  ;

                    }
                    return showStr
                }
            },
        },
        data(){
            return {
                globalData:app.globalData,
                imgVersion:app.globalData.imgVersion,
                imgpath:app.globalData.imgPath + '/member/order/',
                defaultImg:app.globalData.masterDomain + '/static/images/good_default.png',
            }
        },
        mounted(){

        },

        methods:{
            // 点击页面跳转 
            /***
             * @param {*} type 跳转类型  order => 详情   
             */
            toLink(type){
                const that = this;
                let url = ''
                switch(type){
                    case 'pay':
                        uni.$emit('payorder',{objInfo:this.objInfo,ind:this.ind})
                        break;
                    case 'cancel':
                        uni.$emit('cancelorder',{objInfo:this.objInfo,ind:this.ind})
                        break;
                    case 'order':
                        url = `${app.globalData.appConfig && app.globalData.appConfig.cfg_user_index }/orderdetail-travel-${that.objInfo.id}.html`
                        app.linkTo(url,false,false)
                        break;
                    case 'rebuy':
                        url = `${app.globalData.masterDomain}/travel/confirm-order-${that.objInfo.type}-${that.objInfo.proid}.html`
                        app.linkTo(url,false,false)
                        break;
                    case 'showCode':
                        uni.$emit('showwuliu',{objInfo:this.objInfo,ind:this.ind})
                        break;
                    case 'pay_other':
                        url = that.globalData.appConfig.cfg_user_index + '/daipay.html?module=tuan&ordernum=' + that.objInfo.ordernum;
                        app.linkTo(url,false,false)
                        break;
                    case 'refund_cancel':
                        // 取消退款
                        uni.$emit('cancelorder',{objInfo:this.objInfo,ind:this.ind,opt:'refund_cancel'})
                        break;
                    // case 'comment':
                    //     // 取消退款
                    //     uni.$emit('cancelorder',{objInfo:this.objInfo,ind:this.ind,opt:'refund_cancel'})
                    //     break;
                }
            },
            
        },

        
    }
</script>

<style scoped>
     @import './orderlist_travel.css'
</style>